<?php

namespace App\Exports\Test;

use App\Trip\Translate\Niutrans\Translation;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;

class TestExport implements FromCollection
{
    private array $data;

    public function __construct(array $data)
    {
        $this->data = $data;
    }

    /**
     * @return Collection
     * @throws Exception
     * @throws GuzzleException
     */
    public function collection(): Collection
    {
        $data = [];

        foreach ($this->data as $key => $datum) {
            $data[$key]['origin']    = $datum;
            $data[$key]['translate'] = (new Translation($datum))->translate()->getTranslation();
        }

        return collect($data);
    }
}
